import { var_split, string_function } from "../utils";



export class HandlerHttpHeaderToSnakeCase implements IStringHandler {

    convertStr(text: string): string {
        // let text_list = var_split(text);
        return string_function(text, (p: string) => {
            let convert_ele = (_ele: string) => {
                if (/[_a-zA-Z]+/.test(_ele)) {
                    if (_ele.length > 1) {
                        return _ele[0].toLowerCase() + _ele.substr(1);
                    } else {
                        return _ele.toLowerCase();
                    }

                } else {
                    return _ele
                }
            }
            let char_array = p.split("-")
            let convert_array = []
            for (let ele of char_array) {
                convert_array.push(convert_ele(ele));
            }
            return convert_array.join("_");


        });

    }
}